package com.wzk.travelspringboot.enumerate;

/**
 * @Author: WangZiKang
 * @Date: 2025/1/5 13:18
 */
public enum StateEnum {
    ENABLE(1,"可用"),
    FREEZE(2,"冻结"),
    REVOKED(3,"注销"),
    ERROR(4,"异常情况");
    private final int code;
    private final String description;

    // 构造函数
    StateEnum(int code, String description) {
        this.code = code;
        this.description = description;
    }

    // 获取code值
    public int getCode() {
        return code;
    }

    // 获取description值
    public String getDescription() {
        return description;
    }

    // 根据code值获取对应的枚举描述
    public static String fromCode(int code) {
        for (StateEnum state : StateEnum.values()) {
            if (state.getCode() == code) {
                return state.getDescription();
            }
        }
        return ERROR.getDescription(); // 如果未匹配，返回UNKNOWN
    }

}
